﻿using System;
using Microsoft.Practices.ObjectBuilder;
using Microsoft.Practices.CompositeWeb.Web.UI;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using Microsoft.Practices.Web.UI.WebControls;
using DataAccess.BusinessEntities;

namespace Locator.Stores.Views
{
    public partial class UsersStores : UserControl, IUsersStoresView
    {
        private UsersStoresPresenter presenter;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                this.presenter.OnViewInitialized();
            }

            this.presenter.OnViewLoaded();
        }

        [CreateNew]
        public UsersStoresPresenter Presenter
        {
            get { return this.presenter; }
            set
            {
                if (value == null)
                    throw new ArgumentNullException("value");

                this.presenter = value;
                this.presenter.View = this;
            }
        }

        /// <summary>
        /// Sets the stores.
        /// </summary>
        /// <param name="stores">The stores.</param>
        public void SetStores(List<Store> stores)
        {
            this.StoresDataSource.DataSource = stores;
        }

        protected void StoresDataSource_Deleted(object sender, ObjectContainerDataSourceStatusEventArgs e)
        {
            this.presenter.OnStoreDeleted((Store)e.Instance);
        }

        protected void StoreSearchLinkButton_Click(object sender, EventArgs e)
        {
            this.presenter.OnStoreSearchClicked();
        }
    }
}

